package com.wenhuitec.productlib.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.gzwh.weblib.bean.NzProductCategory;
import com.gzwh.weblib.bean.NzStore;
import com.gzwh.weblib.bean.Result;
import com.gzwh.weblib.utils.MyObserver;
import com.gzwh.weblib.utils.RequestUtils;
import com.wenhuitec.productlib.R;
import com.wenhuitec.productlib.ui.adapter.CategoryManagerAdapter;
import com.wenhuitec.sysui.TitleBuilder;

import java.util.List;

public class CategoryManagerActivity extends AppCompatActivity {

    private Context mContext;

    private RecyclerView mLv;

    private CategoryManagerAdapter mCategoryManagerAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_product_category);
        this.mContext = this;
        new TitleBuilder(this)
                .setTitleText("分类管理")
//                .setLeftIco(R.drawable.yp)
                .setLeftIcoListening((view) -> finish());
        findViewById(R.id.addCategory).setOnClickListener(view -> {
            startActivity(new Intent(mContext, EditCategoryActivity.class));
        });
        findViewById(R.id.cateSortBut).setOnClickListener(view -> {
            startActivity(new Intent(mContext, CategorySortActivity.class));
        });
        mLv = (RecyclerView) findViewById(R.id.cateRv);
    }


    @Override
    public void onResume() {
        super.onResume();
        RequestUtils.getCategoryList(mContext, new MyObserver<List<NzProductCategory>>(mContext, false) {
            @Override
            public void onSuccess(Result<List<NzProductCategory>> result) {
                mLv.setLayoutManager(new LinearLayoutManager(mContext));//设置布局管理器
                mCategoryManagerAdapter = new CategoryManagerAdapter(mContext, result.getResult(), null);
                mLv.setAdapter(mCategoryManagerAdapter);
            }

            @Override
            public void onFailure(Throwable e, String errorMsg) {

            }
        });
    }
}
